package com.open.center.jpa.model.page;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Range;

import org.springframework.data.domain.PageRequest;

/**
 * 分页查询
 *
 * @author Riche's
 * @since 2025/5/23
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class PageQuery extends Query {

    @Range(min = 1, max = 1000, message = "页码取值范围 1~1000页")
    private int page = 1;

    @Range(min = 1, max = 500, message = "每页记录数取值范围 1~500条")
    private int size = 10;

    public PageRequest getRequest() {
        return PageRequest.of(this.getPage() - 1, this.getSize(), this.sort());
    }

}
